package com.matt.controller.web;

import com.matt.commons.model.StatusResponse;
import com.matt.domain.WorkDate;
import com.matt.domain.article.Article;
import com.matt.domain.vo.WorkDateVo;
import com.matt.foundation.utils.DateUtil;
import com.matt.repository.WorkDateRepository;
import com.matt.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Api(tags ="上班日")
@RestController
@RequestMapping("/web/workDate")
public class WebWorkDateController {
	 @Autowired
	 private WorkDateRepository workDateRepository;

	 @ApiOperation(value = "获取列表",httpMethod = "POST")
	 @RequestMapping(value = "/getList")
	 public StatusResponse getList(String beginDate, String endDate) {
	 	if (StringUtils.equals(beginDate,"null") || StringUtils.equals(endDate,"null")  ){
			beginDate= null;
			endDate= null;
		}
		 List<WorkDate>  list = workDateRepository.findByWorkDateDayList(DateUtil.parseToDateMilis(beginDate),DateUtil.parseToDateMilis(endDate));
		 List<WorkDateVo> workDateVoList = new ArrayList<>();
		 for (int i = 0; i <list.size() ; i++) {
			 WorkDateVo workDateVo = new WorkDateVo();
			 workDateVo.setWorkDate(DateUtil.convertStr(list.get(i).getWorkDate()));
			 workDateVoList.add(workDateVo);
		 }
	     return StatusResponse.success(workDateVoList);
	 }


	@ApiOperation(value = "传时间查询是否是工作日",httpMethod = "POST")
	@RequestMapping(value = "/get")
	public StatusResponse get(String  workDate) {
		WorkDate w = workDateRepository.findByWorkDate(DateUtil.parseToDateMilisV3(workDate));
		if (Objects.nonNull(w)){
			return StatusResponse.success(true);
		}else {
			return StatusResponse.success(false);
		}

	}



}
